package bulletbehavior 
{
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author morgan
	 */
	public class SplitBehavior extends BulletBehavior
	{
		public var num:int;
		public var speed:Number;
		public var arc1:Number;
		public var arc2:Number;
		public var childPattern:BulletPattern;
		public var type:int
		public function SplitBehavior(num:int, speed:Number, arc1:Number, arc2:Number, childPattern:BulletPattern, type:int = -1) 
		{
			this.num = num;
			this.speed = speed;
			this.arc1 = arc1;
			this.arc2 = arc2;
			this.childPattern = childPattern;
			this.type = type;
		}
		
		override public function onActivate(b:Bullet):void 
		{
			var rel:Number = Math.atan2(b.velocity.y, b.velocity.x);
			rel = rel * 180 / 3.14159;
			for (var i:int = 0; i < num; i++)
			{
				var angle:Number = 0;
				if (num == 1) { angle = arc1 + rel; }
				else
				{
					angle = (arc2 - arc1) * (i / (num - 1)) + arc1 + rel;
				}
				angle = angle / 180 * 3.14159;
				var vx:Number = Math.cos(angle) * speed;
				var vy:Number = Math.sin(angle) * speed;
				var t:int = this.type;
				if (this.type == -1)
				{
					t = b.type;
				}
				GameState.ref.makeBullet(t, b.x, b.y, vx, vy, childPattern);
			}
			super.onActivate(b);
		}
		
	}

}